package com.spring.applicationEven_annotation_demo;


import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

import java.util.List;


public class EmailService implements ApplicationEventPublisherAware {

	private List<String> blackList;
	private ApplicationEventPublisher publisher;

	public void setBlackList(List<String> blackList) {
		this.blackList = blackList;
	}

	public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
		this.publisher = publisher;
	}

	public void sendEmail(String address, String content) {
		if (blackList.contains(address)) {
			publisher.publishEvent(new BlackListEvent(this, address, content));
			publisher.publishEvent(new SecondEvent(this, address, content+"----second"));
			return;
		}
		// send email...
	}
}